package generic.gui.util;

import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.util.ArrayList;

import javax.swing.JComboBox;

@SuppressWarnings("serial")
public class JComboBoxLabelForm <ENTITY> extends JPanelForm {
	
	private JComboBox<?> comboBox;
	private JLabelForm label;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public JComboBoxLabelForm(String label, ArrayList<ENTITY> entity) {
		setLayout(new BorderLayout());
		getLabel().setText("  " +label);
		if (entity != null)
			setComboBox(new JComboBox(entity.toArray()));
		else
			setComboBox(new JComboBox());
		
		add(getLabel(), BorderLayout.NORTH);
		add(getComboBox(), BorderLayout.SOUTH);
	}

	public JComboBox<?> getComboBox() {
		return comboBox;
	}

	public void setComboBox(JComboBox<?> comboBox) {
		this.comboBox = comboBox;
	}

	public JLabelForm getLabel() {
		if (label == null) {
			label = new JLabelForm();	
		}
		return label;
	}

	public void setLabel(JLabelForm label) {
		this.label = label;
	}
	public void setBounds(int x,int y,int width,int height) {
		super.setBounds(x, y, width, height);
	}
	public void addKeyListener(KeyListener l) {
		getComboBox().addKeyListener(l);
	}
	public void addActionListener(ActionListener l) {
		getComboBox().addActionListener(l);
	}
	@Override
	public void grabFocus() {
		getComboBox().grabFocus();
	}
}
